﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


/// <summary>
/// 属性比例结构，比例之和等于1
/// </summary>
public partial struct PropertyProportion :ISerializeStruct
{
    public FixedFloat attack;
    public FixedFloat defensive;
    public FixedFloat speed;
    public FixedFloat jump;
    public FixedFloat skill;

    public PropertyProportion(FixedFloat attack, FixedFloat defensive, FixedFloat speed, FixedFloat jump, FixedFloat skill)
    {
        this.attack = attack;
        this.defensive = defensive;
        this.speed = speed;
        this.jump = jump;
        this.skill = skill;
    }

    /// <summary>
    /// 确保加起来是100
    /// </summary>
    /// <returns></returns>
    public void EnsureSum100()
    {
        //暂去掉defensive
        if(attack  + speed + jump + skill != 100)
        {
            skill = 100 - attack - speed - jump;
        }
    }
    
    public int[] GetPropertiesArr()
    {
        return PropertyProportion2IntArr(this.attack, this.defensive, this.speed, this.jump,this.skill);
    }

    public static int[] PropertyProportion2IntArr(FixedFloat attackProportion, FixedFloat defensiveProportion, FixedFloat speedProportion, FixedFloat jumpProportion,FixedFloat skillProportion)
    {
        var propertyArray = new int[5];
        propertyArray[0] = (int)(attackProportion);
        propertyArray[1] = (int)(defensiveProportion);
        propertyArray[2] = (int)(speedProportion);
        propertyArray[3] = (int)(jumpProportion);
        propertyArray[4] = (int)skillProportion;

        return propertyArray;
    }

    public static PropertyProportion IntArr2PropertyProportion(int[] propertyArray)
    {
        PropertyProportion p = new PropertyProportion();

        p.attack = propertyArray[0];
        p.defensive = propertyArray[1];
        p.speed = propertyArray[2];
        p.jump = propertyArray[3];
        p.skill = propertyArray[4];
        return p;
    }

    /*public void Read(byte[] bytes)
    {
        throw new NotImplementedException();
    }

    public byte[] Write()
    {
        throw new NotImplementedException();
    }*/
}
